<!DOCTYPE html>
<html lang="zh-Hans">
  <head>
    
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>


<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">



  <meta name="description" content="对一个程序员来说,能够无障碍的上网是非常重要的,毕竟现在的计算机科学的重心依然在国外.面对越来越严苛的封锁,提高自己的架梯子技术迫在睫眉."/>




  <meta name="keywords" content="技术, 配置, 杂鱼君的博客" />










  <link rel="alternate" href="/atom.xml" title="杂鱼君的博客">




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=2.6.0" />



<link rel="canonical" href="http://notes.wen.moe/post/build-fluent-net-env.html"/>


<link rel="stylesheet" type="text/css" href="/css/style.css?v=2.6.0" />



  <link rel="stylesheet" type="text/css" href="/lib/fancybox/jquery.fancybox.css" />




  



  <script id="baidu_push">
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>









    <title> 搭建自由的网络环境 - 杂鱼君的博客 </title>
  </head>

  <body><div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/." class="logo">杂鱼君的博客</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>

<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    
      <a href="/">
        <li class="mobile-menu-item">
          
          
            Home
          
        </li>
      </a>
    
      <a href="/archives/">
        <li class="mobile-menu-item">
          
          
            Archives
          
        </li>
      </a>
    
      <a href="/tags">
        <li class="mobile-menu-item">
          
          
            Tags
          
        </li>
      </a>
    
      <a href="/about">
        <li class="mobile-menu-item">
          
          
            About
          
        </li>
      </a>
    
  </ul>
</nav>

    <div class="container" id="mobile-panel">
      <header id="header" class="header"><div class="logo-wrapper">
  <a href="/." class="logo">杂鱼君的博客</a>
</div>

<nav class="site-navbar">
  
    <ul id="menu" class="menu">
      
        <li class="menu-item">
          <a class="menu-item-link" href="/">
            
            
              Home
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/archives/">
            
            
              Archives
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/tags">
            
            
              Tags
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/about">
            
            
              About
            
          </a>
        </li>
      
    </ul>
  
</nav>

      </header>

      <main id="main" class="main">
        <div class="content-wrapper">
          <div id="content" class="content">
            
  
  <article class="post">
    <header class="post-header">
      <h1 class="post-title">
        
          搭建自由的网络环境
        
      </h1>

      <div class="post-meta">
        <span class="post-time">
          2017-03-26
        </span>
        
        
      </div>
    </header>

    
    
  <div class="post-toc" id="post-toc">
    <h2 class="post-toc-title">Contents</h2>
    <div class="post-toc-content">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#服务器端"><span class="toc-text">服务器端</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#客户端"><span class="toc-text">客户端</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#OSX"><span class="toc-text">OSX</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#命令行"><span class="toc-text">命令行</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#GIT"><span class="toc-text">GIT</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#iOS-amp-Android"><span class="toc-text">iOS & Android</span></a></li></ol></li></ol>
    </div>
  </div>


    <div class="post-content">
      
        <h2 id="服务器端"><a href="#服务器端" class="headerlink" title="服务器端"></a>服务器端</h2><p>VPS我购买的是<a href="https://www.vultr.com/" target="_blank" rel="external">vultr</a>:<br><a href="https://www.vultr.com/?ref=6913997" target="_blank" rel="external"><img src="https://www.vultr.com/media/banner_1.png" width="728" height="90"></a><br>最便宜的是2.5刀一个月,东京的服务器延迟还可以接受,系统使用的是<code>ubuntu server 16.04</code></p>
<p>服务器上安装的是python版本的<code>shadowsocks</code>,<em>最近发现还有go语言版本的,下次安装一个试试</em>安装方式很简单:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">apt-get install update</div><div class="line">apt-get install install python-setuptools &amp;&amp; easy_install pip</div><div class="line">pip install shadowsocks</div></pre></td></tr></table></figure>
<p>安装完成以后,需要你手动撸一个配置文件:</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">&#123;</div><div class="line">    "server":"45.32.37.200",  //服务器的IP地址</div><div class="line">    "local_address":"127.0.0.1",</div><div class="line">    "local_port":1080,</div><div class="line">    "port_password":&#123;  //对外的端口以及对应的密码</div><div class="line">         "8388":"foobar1",  </div><div class="line">         "8389":"foobar2",</div><div class="line">         "8390":"foobar3",</div><div class="line">         "8391":"foobar4"</div><div class="line">    &#125;,</div><div class="line">    "timeout":300,</div><div class="line">    "method":"aes-256-cfb",  //加密方式</div><div class="line">    "fast_open": false</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>保存在<code>~/c.json</code>.</p>
<p>配置好了以后就可以启动shadowsocks了:</p>
<figure class="highlight stylus"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ssserver -c ss<span class="selector-class">.json</span> -d start</div></pre></td></tr></table></figure>
<h2 id="客户端"><a href="#客户端" class="headerlink" title="客户端"></a>客户端</h2><h3 id="OSX"><a href="#OSX" class="headerlink" title="OSX"></a>OSX</h3><p>客户端的选择很多,我使用的是<code>shadowsocksX-NG</code>:<br><img src="http://7xkdfx.com1.z0.glb.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-08-27%20%E4%B8%8B%E5%8D%8812.35.01.png" alt="osx客户端"></p>
<p>安装好了以后,在<code>服务器设置</code>里面加入你的配置:<br><em>注意我给服务器绑定了域名,这样的好处是以后更换服务器不需要再改客户端配置,只要改下dns的设置就可以</em><br><img src="http://7xkdfx.com1.z0.glb.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202017-08-27%20%E4%B8%8B%E5%8D%8812.38.48.png" alt="OSX客户端2"></p>
<p>要注意加密方式以及端口和密码的对应.<br>这样子设置好了以后,打开<code>shadowsocksX-NG</code>就可以畅游网络了.</p>
<h3 id="命令行"><a href="#命令行" class="headerlink" title="命令行"></a>命令行</h3><p>对于普通人来说,上面的步骤基本就能满足需求了,但是对一个程序员来说还是不够的,尤其是特别依赖命令行交互的后端开发.由于<code>shadowsocksX-NG</code>为我们自动设置好了<code>HTTP代理</code>,由于我用的是<code>zsh</code>,因此只需要在<code>~/.zshrc</code>中加入这样一行:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">alias</span> pp=<span class="string">'env http_proxy=http://127.0.0.1:1087 https_proxy=http://127.0.0.1:1087'</span></div></pre></td></tr></table></figure>
<p>设置好了以后,在需要走代理的命令前面加入<code>pp</code>.如:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">curl ip.gs <span class="comment">#直接连接</span></div><div class="line">pp curl ip.gs <span class="comment">## 走代理</span></div></pre></td></tr></table></figure>
<p>效果如下:</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">▶ <span class="selector-tag">curl</span> <span class="selector-tag">ip</span><span class="selector-class">.sb</span></div><div class="line">112<span class="selector-class">.64</span><span class="selector-class">.63</span><span class="selector-class">.157</span></div><div class="line"></div><div class="line">▶ <span class="selector-tag">pp</span> <span class="selector-tag">curl</span> <span class="selector-tag">ip</span><span class="selector-class">.sb</span></div><div class="line">45<span class="selector-class">.76</span><span class="selector-class">.101</span><span class="selector-class">.67</span></div></pre></td></tr></table></figure>
<p>可以看到,加了<code>pp</code>以后,显示的ip是我们VPS的ip.</p>
<p><em>SOCK5代理转HTTP代理</em></p>
<p>如果你用的客户端软件不会自动把<code>sock5</code>代理转成<code>http/https</code>代理,那么我们需要额外做一些工作,借助<code>polipo</code>这个软件手动把代理类型转换一下:</p>
<figure class="highlight zsh"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">brew install polipo</div></pre></td></tr></table></figure>
<p>安装好了以后,只需要告诉<code>polipo</code> <code>sock5</code>代理的端口:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">alias</span> pp=<span class="string">'env http_proxy=http://127.0.0.1:8123 https_proxy=http://127.0.0.1:8123'</span>  <span class="comment">#8123 是polipo默认的端口</span></div><div class="line"><span class="built_in">alias</span> startpp=<span class="string">'nohup polipo socksParentProxy=127.0.0.1:1086 proxyAddress=0.0.0.0 &amp;'</span></div></pre></td></tr></table></figure>
<p>只要在系统启动的时候,执行一次<code>startpp</code>,以后就可以使用<code>pp</code>来代理你需要的命令了.</p>
<h3 id="GIT"><a href="#GIT" class="headerlink" title="GIT"></a>GIT</h3><p>在使用git来提交代码的时候,你会发现如果使用的是<code>https</code>协议的话,那么加<code>pp</code>是可以走代理的,但是如果使用的是<code>git</code>协议,因为<code>git</code>协议走的是<code>ssh</code>,因此我们需要修改<code>ssh</code>的配置,配置文件在<code>~/.ssh/config</code>:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">Host github.com</div><div class="line">User git</div><div class="line">ProxyCommand nc -x 127.0.0.1:1086 %h %p   <span class="comment">#1086是你的http协议的端口,如果使用polipo转换,那么就是默认的8123端口</span></div></pre></td></tr></table></figure>
<p>感受一下极速clone代码的快感吧.</p>
<h3 id="iOS-amp-Android"><a href="#iOS-amp-Android" class="headerlink" title="iOS &amp; Android"></a>iOS &amp; Android</h3><p>移动设备上配置方式也类似,iOS的代理软件推荐<code>surge</code>,<code>shadowrockets</code>, Android上也有类似的软件,配置方式也可参考OSX的配置.</p>

      
    </div>

    
      
      

  <div class="post-copyright">
    <p class="copyright-item">
      <span>Author: </span>
      <a href="http://notes.wen.moe">zakokun</a>
    </p>
    <p class="copyright-item">
      <span>Link: </span>
      <a href="http://notes.wen.moe/post/build-fluent-net-env.html">http://notes.wen.moe/post/build-fluent-net-env.html</a>
    </p>
    <p class="copyright-item">
      <span>License: </span>
      
      <a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/" target="_blank">知识共享署名-非商业性使用 4.0 国际许可协议</a>
    </p>
  </div>



      
      
    

    
      <footer class="post-footer">
        
          <div class="post-tags">
            
              <a href="/tags/技术/">技术</a>
            
              <a href="/tags/配置/">配置</a>
            
          </div>
        
        
        
  <nav class="post-nav">
    
      <a class="prev" href="/post/go-string-implode-diff-way.html">
        <i class="iconfont icon-left"></i>
        <span class="prev-text nav-default">go 语言中哪种字符串拼接的方式最高效?</span>
        <span class="prev-text nav-mobile">Prev</span>
      </a>
    
    
      <a class="next" href="/post/2016-year-person-summarize.html">
        <span class="next-text nav-default">2016年年终总结</span>
        <span class="prev-text nav-mobile">Next</span>
        <i class="iconfont icon-right"></i>
      </a>
    
  </nav>

      </footer>
    

  </article>


          </div>
          
  <div class="comments" id="comments">
    
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    
  </div>


        </div>
      </main>

      <footer id="footer" class="footer">

  <div class="social-links">
    
      
        
          <a href="mailto:me@wen.moe" class="iconfont icon-email" title="email"></a>
        
      
    
      
    
      
    
      
    
      
    
      
    
      
    
      
    
      
    
      
    
      
    
      
    
      
        
          <a href="https://www.instagram.com/zakokun" class="iconfont icon-instagram" title="instagram"></a>
        
      
    
    
    
  </div>


<div class="copyright">
  <span class="power-by">
    Powered by <a class="hexo-link" href="https://hexo.io/">Hexo</a>
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    Theme -
    <a class="theme-link" href="https://github.com/ahonn/hexo-theme-even">Even</a>
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    Hosted by <a class="theme-link" href="https://pages.coding.me" style="font-weight: bold">Coding Pages</a>
  </span>

  <span class="copyright-year">
    
    &copy;
    
      2014 -
    
    2017

    <span class="heart">
      <i class="iconfont icon-heart"></i>
    </span>
    <span class="author">zakokun</span>
  </span>
</div>

      </footer>

      <div class="back-to-top" id="back-to-top">
        <i class="iconfont icon-up"></i>
      </div>
    </div>

    
  
  <script type="text/javascript">
    var disqus_config = function () {
        this.page.url = 'http://notes.wen.moe/post/build-fluent-net-env.html';
        this.page.identifier = 'post/build-fluent-net-env.html';
        this.page.title = '搭建自由的网络环境';
    };
    (function() {
    var d = document, s = d.createElement('script');

    s.src = '//evanszhang.disqus.com/embed.js';

    s.setAttribute('data-timestamp', +new Date());
    (d.head || d.body).appendChild(s);
    })();  
  </script>




    
  





  
    <script type="text/javascript" src="/lib/jquery/jquery-3.1.1.min.js"></script>
  

  
    <script type="text/javascript" src="/lib/slideout/slideout.js"></script>
  

  
    <script type="text/javascript" src="/lib/fancybox/jquery.fancybox.pack.js"></script>
  


    <script type="text/javascript" src="/js/src/even.js?v=2.6.0"></script>
<script type="text/javascript" src="/js/src/bootstrap.js?v=2.6.0"></script>

  </body>
</html>
